// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

// 预编译指令，确保头文件只被包含一次

#include "ModularPawn.h"
#include "Teams/LyraTeamAgentInterface.h"

// 包含基类ModularPawn和团队代理接口

#include "LyraPawn.generated.h"

// 包含Unreal的生成代码头文件

class AController;
class UObject;
struct FFrame;

// 前向声明类，减少编译依赖

/**
 * ALyraPawn
 */
UCLASS()
class LYRAGAME_API ALyraPawn : public AModularPawn, public ILyraTeamAgentInterface
{
    GENERATED_BODY()

    // Unreal的UCLASS宏，生成必要的反射代码

public:

    ALyraPawn(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

    // 构造函数

    //~AActor interface
    virtual void PreInitializeComponents() override;
    virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
    //~End of AActor interface

    // 重写AActor接口的方法

    //~APawn interface
    virtual void PossessedBy(AController* NewController) override;
    virtual void UnPossessed() override;
    //~End of APawn interface

    // 重写APawn接口的方法

    //~ILyraTeamAgentInterface interface
    virtual void SetGenericTeamId(const FGenericTeamId& NewTeamID) override;
    virtual FGenericTeamId GetGenericTeamId() const override;
    virtual FOnLyraTeamIndexChangedDelegate* GetOnTeamIndexChangedDelegate() override;
    //~End of ILyraTeamAgentInterface interface

    // 实现团队代理接口的方法

protected:
    // Called to determine what happens to the team ID when possession ends
    virtual FGenericTeamId DetermineNewTeamAfterPossessionEnds(FGenericTeamId OldTeamID) const
    {
        // This could be changed to return, e.g., OldTeamID if you want to keep it assigned afterwards, or return an ID for some neutral faction, or etc...
        return FGenericTeamId::NoTeam;
    }

    // 受保护方法：确定当控制结束时团队ID应该变成什么

private:
    UFUNCTION()
    void OnControllerChangedTeam(UObject* TeamAgent, int32 OldTeam, int32 NewTeam);

    // 私有UFUNCTION：当控制器改变团队时的回调函数

private:
    UPROPERTY(ReplicatedUsing = OnRep_MyTeamID)
    FGenericTeamId MyTeamID;

    // 私有属性：复制团队ID，当复制时触发OnRep_MyTeamID

    UPROPERTY()
    FOnLyraTeamIndexChangedDelegate OnTeamChangedDelegate;

    // 私有属性：团队改变时的委托

private:
    UFUNCTION()
    void OnRep_MyTeamID(FGenericTeamId OldTeamID);

    // 私有UFUNCTION：当MyTeamID在客户端复制时的回调
};